﻿using JyCommonKit.ObjectPoolKit;

namespace JyCommonKit.Examples
{
    /// <summary>
    /// test object pool
    /// </summary>
    class TestObjectPool
    {
        private void Test()
        {
            // get objectpool object
            ObjectPool<TestObjectPool_Obj> pool = new ObjectPool<TestObjectPool_Obj>(10, 20, TestObjectPool_Obj.GetObj, TestObjectPool_Obj.Release);

            // get some object
            var obj1 = pool.Dequeue();
            // do obj some thing
            // ...
            var obj2 = pool.Dequeue();
            var obj3 = pool.Dequeue();

            pool.Enqueue(obj1);
            pool.Enqueue(obj2);
            pool.Enqueue(obj3);

            // if you want release pool
            pool.Dispose();
        }
    }

    internal class TestObjectPool_Obj
    {
        public static TestObjectPool_Obj GetObj()
        {
            return new TestObjectPool_Obj();
        }

        public static void Release(TestObjectPool_Obj obj)
        {

        }
    }

}
